﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace Esint.Common.Image
{
    public class BarCode
    {
        public static byte[] GetBarCode(int width, int height, string number, string fontFamily, int fontSize)
        {
            Bitmap image = new System.Drawing.Bitmap(width, height);
            Graphics g = Graphics.FromImage(image); 
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            try
            {

                g.Clear(Color.White);
                Font font = new System.Drawing.Font(fontFamily, fontSize);
                System.Drawing.SolidBrush brush = new System.Drawing.SolidBrush(Color.Black);
                g.DrawString(number, font, brush, 5, 5);
                image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);

            }
            catch
            { }
            finally
            {
                g.Dispose();
                image.Dispose();
            }
            return ms.ToArray();
        }
    }
   
}
